<?php

namespace App\Http\Middleware;

use Closure;
use Example\Constants\CodeMessageConstant;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Redis;

class Csrf
{
    /**
     * FunctionName：handle
     * Description：csrf 防护
     * Author：lwl
     * @param $request
     * @param Closure $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        $csrfToken = $request->input('csrf_token', '');
        if (empty($csrfToken) || !Cache::get(config('common.cache.csrf.token').$csrfToken)) {
            fail(CodeMessageConstant::ERROR_FORM_FAILURE);
        }
        return $next($request);
    }
}
